#  Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#  Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
#  Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
#  Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
#  Vestibulum commodo. Ut rhoncus gravida arcu.
#  Xiaosi Artificial Intelligence Copyright reserved/No tampering or code theft allowed
#  Powered by XiaoSi Artificial Intelligence on Sir Shao | Sir Wu | Sir Li
#  Thank you again to the optimization team
import json
import os
import sys
import webbrowser
from concurrent.futures import ThreadPoolExecutor

import numpy as np
import requests


# 优化算法
def optimized_algorithm(array):
    return np.sum(array)  # 使用NumPy进行快速求和


# 使用多线程
def run_concurrently(functions, args):
    with ThreadPoolExecutor() as executor:
        results = list(executor.map(lambda f: f(*args), functions))
    return results


print('=*=*=*=*=*= 欢迎使用 Xiao_Si_NEXT =*=*=*=*=*=')
print('=*=*=*=*=*=Welcome to Xiao_Si-NEXT=*=*=*=*=*=')
print('|1. Exit |  2. Update |  3. Manual Consultation | 4. Start Using |  Please Make Your Choice/=*=*=* &&')
xs = "| 1.退出 |" " 2.更新 |" " 3.手册咨询 | 4.开始使用 | " "请做出你的选择 /=*=*=*=*>"
name = input(xs)
if name == "1":
    sys.exit()
if name == '2':
    url = "https://gitee.com/dirde12078904/xiao-si/releases"
    # 打开默认浏览器并显示指定的URL
    webbrowser.open(url)
    sys.exit()
if name == '3':
    url = "https://gitee.com/dirde12078904/technical-white-paper-sharing"
    # 打开默认浏览器并显示指定的URL
    webbrowser.open(url)
    sys.exit()
if name == '4':
    os.system('echo.')
print('***************************************************************************************************')
print(
    '\033[1;31;43m|     ::::-++++++++++++-         .::::-++++++++++++:      .:::-==+++************++++=          '
    '|\033[0m')
print(
    '\033[1;31;43m|      :----+***********=       .----=*********+*+.    .:---=++***++++++++++++++++**+          '
    '|\033[0m')
print(
    '\033[1;31;43m|       .----=+*++++++++*+.    :----=*+++++++++*-     -----+**++++++++***********++*=          '
    '|\033[0m')
print(
    '\033[1;31;43m|         :----+*++++++++*+:  :----+*++++++++*+:     -----+*++++++++*++========+++**=          '
    '|\033[0m')
print(
    '\033[1;31;43m|          :----=*++++++++**-:----+*++++++++*=.     .-----*++++++++*-             ...          '
    '|\033[0m')
print(
    '\033[1;31;43m|           .----=+*++++++++*+--=+*+++++++**-       :----=*+++++++*+                           '
    '|\033[0m')
print(
    '\033[1;31;43m|             :----+*++++++++*+=*++++++++*+:        :----=*+++++++++-                          '
    '|\033[0m')
print(
    '\033[1;31;43m|              :----=*++++++++**++++++++*=          .-----+*++++++++*++=-:..                   '
    '|\033[0m')
print(
    '\033[1;31;43m|               .----=+*+++++++++++++++*-            :----=+*+++++++++******++=-:.             '
    '|\033[0m')
print(
    '\033[1;31;43m|                 :----+*++++++++++++++.              .:----++***++++++++++++****++-           '
    '|\033[0m')
print(
    '\033[1;31;43m|                .----=++++++++++++++++-                 .:::-==++*******+++++++++**+:         '
    '|\033[0m')
print(
    '\033[1;31;43m|               :----+*++++++++++++++++*+.                     ..::-===+++**++++++++**.        '
    '|\033[0m')
print(
    '\033[1;31;43m|             .----=+*++++++++**++++++++**-                          .:---=+*++++++++*-        '
    '|\033[0m')
print(
    '\033[1;31;43m|            :----=**++++++++*==+*++++++++*=                          .-----+*+++++++*=        '
    '|\033[0m')
print(
    '\033[1;31;43m|           :----+*++++++++*+=---+*++++++++*+.                        .-----+*+++++++*=        '
    '|\033[0m')
print(
    '\033[1;31;43m|         .----=+*++++++++*=.:----+*++++++++**-     ::...-=-:...     .----=+*++++++++*:        '
    '|\033[0m')
print(
    '\033[1;31;43m|        :----=*+++++++++*=   .----=*+++++++++*=    -----+******++++++++++**++++++++*+         '
    '|\033[0m')
print(
    '\033[1;31;43m|       :----+*++++++++**:     .----=+*++++++++*+:  -----++++++++***+++*++++++++++**=          '
    '|\033[0m')
print(
    '\033[1;31;43m|    .----=**+******+*+.        -----+*+******+**- -----+***+++++++++++++++*****+=:            '
    '|\033[0m')
print(
    '\033[1;31;43m|    :-::-=+++++++++++=           ::::-=++++++++++*+:::::=++++++**********++++=-:              '
    '|\033[0m')
print(
    '\033[1;31;43m*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Xiao_Si_AI_NEXT '
    '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\033[0m')
print(
    '\033[1;31;43m|----------------------------------Xiao_Si_AI_NEXT Developer Beta '
    'Version---------------------|\033[0m')
print(
    '\033[1;31;40m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=- 你好,我是 Xiao_Si_AI_NEXT '
    '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-\033[0m')
print('\033[1;36m     - > Xiaosi Artificial Intelligence Program < -\033[0m')
print('\033[1;31m            -- 版本所有权 -- 更新查看网址 -- \033[0m')
print('\033[1;31m = > https://gitee.com/dirde12078904/xiao-si/releases < =\033[0m')
API_KEY = '2iU0QJiVJBQqCKOLW5Jf8aS9'
SECRET_KEY = 'Aqg401HImuqRaprlpctYDLO1TnkClH6c'


def main():
    print('\033[1;36m作为你的智能伙伴，我既能写文案、想点子，又能陪你聊天、答疑解惑\033[0m')
    print('         请输入你想问的问题(注：什么问题不问,直接回车及为退出)')
    print("=-=-=-=-=-=-=-=-=-=-=-=-= 说 出 你 的 问 题 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
    xiao_si = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + get_access_token ()
    while 1:
        s = input()
        # 注意message必须是奇数条
        payload = json.dumps({
            "messages": [
                {
                    "role": "user",
                    "content": s
                }
            ]
        })
        headers = {
            'Content-Type': 'application/json'
        }

        res = requests.request("POST", xiao_si, headers=headers, data=payload).json()
        print("\033[33mXiao Si AI NEXT\033[0m")
        print(res['result'])
        print('The content is generated by AI and cannot be guaranteed to be true and accurate. It is for reference '
              'only')
        print('\033[31;5m  = | = | = | = | = | = | = | = > 内容由AI生成，无法确保真实准确，仅供参考 < = | = | = | = | = | = | = | = | '
              '=\033[0m\r\n')
        print('请输入你想问的问题(注：如果您没问题了,可直接回车,视为退出)')
        print('Please enter the question you want to ask (note: If you have no further questions, you can simply '
              'enter the key, which will be considered as exiting)')
        print("=+=+=+=++=+=+=++=+=+=+说出你的问题+=+=+=+=+=+=+=+=+=++=+=+=+=")


def get_access_token():
    xiao_si = "https://aip.baidubce.com/oauth/2.0/token"
    params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
    return str(requests.post(xiao_si, params=params).json().get("access_token"))


if __name__ == '__main__':
    main()
